package cl.jsoftlabs.gwt.soccer.client.ui.jugadores;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelIconProvider;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.ToolButton;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.user.client.ui.AbstractImagePrototype;

public class TreeMenuJugador extends LayoutContainer {

	public TreeMenuJugador() {
		
		ContentPanel cp = new ContentPanel();  
	    cp.setAnimCollapse(false);  
	    cp.setHeading("Online Users");  
	    cp.setLayout(new FitLayout());  
	    cp.getHeader().addTool(new ToolButton("x-tool-refresh")); 
	    
	    this.add(cp);
		
		TreeStore<ModelData> store = new TreeStore<ModelData>();  
	    TreePanel<ModelData> tree = new TreePanel<ModelData>(store);  
	    tree.setIconProvider(new ModelIconProvider<ModelData>() {  
	  
	      public AbstractImagePrototype getIcon(ModelData model) {  
	        if (model.get("icon") != null) {  
	          return IconHelper.createStyle((String) model.get("icon"));  
	        } else {  
	          return null;  
	        }  
	      }  
	  
	    });  
	    tree.setDisplayProperty("name");
		
		ModelData m = newItem("Family", null);  
	    store.add(m, false);  
	    tree.setExpanded(m, true);  
	  
	    store.add(m, newItem("Darrell", "user"), false);  
	    store.add(m, newItem("Maro", "user-girl"), false);  
	    store.add(m, newItem("Lia", "user-kid"), false);  
	    store.add(m, newItem("Alec", "user-kid"), false);  
	    store.add(m, newItem("Andrew", "user-kid"), false);  
	  
	    m = newItem("Friends", null);  
	    store.add(m, false);  
	    tree.setExpanded(m, true);  
	    store.add(m, newItem("Bob", "user"), false);  
	    store.add(m, newItem("Mary", "user-girl"), false);  
	    store.add(m, newItem("Sally", "user-girl"), false);  
	    store.add(m, newItem("Jack", "user"), false);  
	  
	    cp.add(tree);
	}
	
	private ModelData newItem(String text, String iconStyle) {  
	    ModelData m = new BaseModelData();  
	    m.set("name", text);  
	    m.set("icon", iconStyle);  
	    return m;  
	  } 

}
